//
//  OrderTableViewCell.m
//  BaseFrame
//
//  Created by 孟学浩 on 2017/4/5.
//  Copyright © 2017年 com.mxh. All rights reserved.
//

#import "OrderTableViewCell.h"

@interface OrderTableViewCell()

@property (nonatomic,strong) UIImageView *imgView;
@property (nonatomic,strong) UILabel *infoLabel;
@property (nonatomic,strong) UILabel *timeLabel;

@end

@implementation OrderTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = 0;
        self.separatorInset = UIEdgeInsetsZero;
        if ([self respondsToSelector:@selector(setLayoutMargins:)]) {
            self.layoutMargins = UIEdgeInsetsZero;
        }
        _imgView = [UIImageView new];
        _imgView.contentMode = UIViewContentModeScaleAspectFit;
        
        _infoLabel = [UILabel new];
        _infoLabel.numberOfLines = 0;
        _infoLabel.font = DEF_FontSize_13;
        
        _timeLabel = [UILabel new];
        _timeLabel.textColor = [UIColor blackColor];
        _timeLabel.font = DEF_FontSize_12;
        _timeLabel.textAlignment = NSTextAlignmentRight;
        
        [self.contentView addSubview:_imgView];
        [self.contentView addSubview:_infoLabel];
        [self.contentView addSubview:_timeLabel];
    }
    
    return self;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    _imgView.frame = CGRectMake(15, 0, self.frame.size.height-15, self.frame.size.height-15);
    _imgView.center = CGPointMake(_imgView.center.x, self.frame.size.height/2.);
    
    _infoLabel.frame = CGRectMake(CGRectGetMaxX(_imgView.frame)+5, 0, SCREEN_WIDTH - CGRectGetMaxX(_imgView.frame) - 10, self.frame.size.height);
    _timeLabel.frame = CGRectMake(SCREEN_WIDTH-150, 0, 140, 20);
}

- (void)setDataDictionary:(NSDictionary *)dataDictionary{
    _dataDictionary = dataDictionary;
    _imgView.image = [UIImage imageNamed:@"img"];
    _timeLabel.text = @"2017-04-06";
    NSString *title = @"公司名称";
    NSString *info = @"最新产品 功率小 效率高";
    NSString *money = @"历史最低价      ¥599";
    NSString *temp = [NSString stringWithFormat:@"%@\n%@\n%@",title,info,money];
    
    NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:temp];
    [attStr addAttribute:NSForegroundColorAttributeName value:getColor(@"545454") range:[temp rangeOfString:info]];
    [attStr addAttribute:NSForegroundColorAttributeName value:getColor(redColor) range:[temp rangeOfString:money]];
    
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:4];//调整行间距
    [attStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [temp length])];
    
    _infoLabel.attributedText = attStr;
}

- (void)setModel:(OrderNowModel *)model{
    _model = model;
    [_imgView sd_setImageWithURL:[NSURL URLOffsetIPWithString:_model.ofgPicture] placeholderImage:[UIImage imageNamed:@"image"]];
    _timeLabel.text = _model.hoTime;
    NSString *title = _model.ofgName;
    NSString *info = _model.ofgProperty;
    NSString *money = [NSString stringWithFormat:@"¥%@",_model.ofgPrice];
    NSString *temp = [NSString stringWithFormat:@"%@\n%@\n%@",title,info,money];
    
    NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:temp];
    [attStr addAttribute:NSForegroundColorAttributeName value:getColor(@"545454") range:[temp rangeOfString:info]];
    [attStr addAttribute:NSForegroundColorAttributeName value:getColor(redColor) range:[temp rangeOfString:money]];
    
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:4];//调整行间距
    [attStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [temp length])];
    
    _infoLabel.attributedText = attStr;
}

@end
